package com.xoa.controller.crm;

import com.xoa.model.crm.CrmManager;
import com.xoa.model.crm.CrmRole;
import com.xoa.service.crm.CrmRoleService;
import com.xoa.util.ToJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by qiyang on 2019/7/22.
 */
@Controller
@RequestMapping("/crmRole")
public class CrmRoleController {

    @Autowired
    private CrmRoleService crmRoleService;

    @ResponseBody
        @RequestMapping("/setUpCrmRole")
    public ToJson<Integer> setUpCrmRole(HttpServletRequest request, CrmRole crmRole){
        ToJson json =new ToJson<Integer>(1,"err");
        try {
            Integer data = crmRoleService.setUpCrmRole(crmRole);
            if(data!=null){
                json.setObject(data);
                json.setFlag(0);
                json.setMsg("true");
            }
        }catch(Exception e){
            e.printStackTrace();
        }
        return json;
    }

    @ResponseBody
    @RequestMapping("/selectAll")
    public ToJson<CrmRole> selectAll(HttpServletRequest request){
        ToJson json =new ToJson<Integer>(1,"err");
        try {
            List<CrmRole> data = crmRoleService.selectAll();
            if(data!=null){
                json.setObject(data);
                json.setFlag(0);
                json.setMsg("true");
            }
        }catch(Exception e){
            e.printStackTrace();
        }
        return json;
    }
}
